package com.weetop.cfw.home_page.adapter

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.chad.library.adapter.base.entity.MultiItemEntity
import com.weetop.cfw.R
import com.weetop.cfw.bean.AllSubSiteListBean
import com.weetop.cfw.bean.Level1ItemBean
import com.weetop.cfw.bean.Level2ItemBean
import com.weetop.cfw.utils.EventBusUtils
import com.weetop.cfw.utils.PinyinUtils

class ChooseAddressRVAdapter(dataList:List<MultiItemEntity>):BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder>(dataList) {

    companion object{
        const val TYPE_LEVEL_0 = 0
        const val TYPE_LEVEL_1 = 1
    }

    init {
        addItemType(TYPE_LEVEL_0, R.layout.layout_city_one_level)
        addItemType(TYPE_LEVEL_1, R.layout.layout_city_two_level)
    }

    override fun convert(helper: BaseViewHolder, item: MultiItemEntity?) {
        when (helper.itemViewType){
            TYPE_LEVEL_0 -> {
                val level1ItemBean = item as AllSubSiteListBean.DataBean
                helper.setText(R.id.textProvinceName,level1ItemBean.provname).setText(R.id.textCityFirstLetter,level1ItemBean.flet.toUpperCase())

                helper.itemView.setOnClickListener{
                    val pos = helper.adapterPosition
                    if (level1ItemBean.isExpanded) {
                        collapse(pos)
                    } else {
                        expand(pos)
                    }
                }
            }
            TYPE_LEVEL_1 -> {
                val level2ItemBean = item as AllSubSiteListBean.DataBean.SdataBean
                helper.itemView.setOnClickListener {
                    EventBusUtils.post(level2ItemBean)
                }
                helper.setText(R.id.textCityName,level2ItemBean.sitename)
            }
        }
    }
}